#!/bin/sh

BUILD_SIMULATOR="0"
APP_NAME="HelloWorld"

for arg; do
    if [ "$arg" = "--simulator" ]; then
        BUILD_SIMULATOR="1"
    elif [ "$arg" = "--help" ]; then
        exit 1
    fi
done

if [ "$BUILD_SIMULATOR" = "0" ]; then
    #. /usr/local/openmoko/arm/environment-setup
    #. /usr/local/openmoko/arm/bin/setup-env
    ARM_PATH="/opt/toolchains/arm920t-eabi/bin/"
    QT4_PATH="/usr/local/Trolltech/QtEmbedded-4.6.0-arm/bin/"
    PATH=$QT4_PATH:$ARM_PATH:$PATH
    export PATH
fi

if [ -f Makefile ]; then
    rm Makefile
fi

rm -rf BUILD
if [ "$BUILD_SIMULATOR" = "1" ]; then
    echo " - Building $APP_NAME App (Simulator)"
    qmake "DEFINES += UIKIT_SIMULATOR" && make > /dev/null
else
    echo " - Building $APP_NAME App"
    qmake && make > /dev/null
fi

if [ $? -eq 0 ]; then
    rm -rf $APP_NAME.app/
    cp -R BUILD/App $APP_NAME.app/
    echo "   - $APP_NAME App [ ok ]"
    exit 0
else
    echo "   - $APP_NAME App [ !! ]"
    exit 1
fi

